'use strict';

const Controller = require('egg').Controller;

const {
  PACKAGE_DETAIL_CATCE_KEY,
} = require('../../../../config/redisKey');

class PackageController extends Controller {

  // 详情缓存的KEY
  deatilCatchKey(id) {
    return `${PACKAGE_DETAIL_CATCE_KEY}_${id}`
  }

  async types() {
    const { ctx } = this;
    const data = await ctx.service.package.types();
    ctx.sendSuccess(data);
  }

  // 添加评论
  async addComments() {
    const { ctx } = this;
    ctx.clearCache(this.deatilCatchKey(this.ctx.params.id))
    await ctx.addComments('Package')
  }

  // 删除评论
  async deleteComments() {
    const { ctx } = this;
    ctx.clearCache(this.deatilCatchKey(this.ctx.query.dataId))
    await ctx.deleteComments('Package')
  }
}

module.exports = PackageController;
